﻿@{
    Layout = null;
}

<div>
    <div class="input-group">
        <div class="col-3 pr-0" style="display: none">
            @* <label id="AddReagents-MonitoringId">@ViewData["MonitoringId"]</label> *@
            <label id="AddReagents-Parent-ModalID">@ViewData["ModalID"]</label>
        </div>
        <div class="input-group">
            <div class="col-3 pr-0">
                <span class="input-group-text font-rfs border-radius-noright noRightBorder">名称*</span>
            </div>
            <div class="col-9 pl-0">
                <input id="AddReagents-Name" class="form-control font-rfs border-radius-noleft" />
            </div>
        </div>
        <div class="input-group">
            <div class="col-3 pr-0">
                <span class="input-group-text font-rfs border-radius-noright noRightBorder">类型*</span>
            </div>
            <div class="col-9 pl-0 input-group position-relative">
                <select id="AddReagents-Select-Type" class="form-control font-rfs border-radius-noleft" style="width: 90%" onchange="selectOnchang(this)"></select>
                <div class="col-11 pl-0 input-group position-absolute float-left">
                    <input id="AddReagents-Input-Type" class="form-control font-rfs border-radius-noleft noRightBorder" style="width:100%" placeholder="可输入新的类型" />
                </div>
            </div>
        </div>
        <div class="input-group">
            <div class="col-3 pr-0">
                <span class="input-group-text font-rfs border-radius-noright noRightBorder">有效时长</span>
            </div>
            <div class="col-9 pl-0 input-group">
                <input id="AddReagents-Input-Validity" class="form-control font-rfs border-radius-noleft" style="width:30%" placeholder="整数" maxlength="2" onkeyup="value=value.replace(/[^\d]/g,'')" />
                <span class="input-group-text font-rfs border-radius-noradius noRightBorder noLeftBorder" style="width:30%">时长单位</span>
                <select id="AddReagents-Input-ValidityUnit" class="form-control font-rfs border-radius-noleft" style="width:40%">
                    <option>天</option>
                    <option>周</option>
                    <option>月</option>
                    <option>年</option>
                </select>
            </div>
        </div>
    </div>
    <div class="text-right">
        <button id="AddReagents-confirm" class="btn btn-primary font-rfs">确定</button>
        <button id="AddReagents-cancel" type="button" class="btn btn-info font-rfs" data-dismiss="modal">取消</button>
    </div>
</div>

<script>

    $(document).ready(function () {
        LoadType();
    });

    function LoadType() {
        $.post("GetReagentType", {
        }, function (data) {
            for (var i = 0; i < data.length; i++) {
                $("#AddReagents-Select-Type").append(new Option(data[i].type));
            }
            $("#AddReagents-Select-Type").prepend(new Option("", ""));
            $("#AddReagents-Select-Type").val("");
        });
    }

    function selectOnchang(obj) {
        $("#AddReagents-Input-Type").val($("#AddReagents-Select-Type").find("option:selected").text());
    };

    $("#AddReagents-confirm").click(function () {
        if ($.trim($("#AddReagents-Name").val()).length == 0) {
            alert("试剂名称不能为空！");
            $("#AddReagents-Name").addClass('error-style');
            return false;
        }
        if ($.trim($("#AddReagents-Input-Type").val()).length == 0) {
            alert("试剂类型不能为空！");
            $("#AddReagents-Input-Type").addClass('error-style');
            return false;
        }
        if ($.trim($("#AddReagents-Input-Validity").val()).length == 0) {
            alert("有效时长不能为空！");
            $("#AddReagents-Input-Validity").addClass('error-style');
            return false;
        }

        var jsonStr = {};
        jsonStr["Name"] = $.trim($("#AddReagents-Name").val());
        jsonStr["Type"] = $.trim($("#AddReagents-Input-Type").val());
        jsonStr["Validity"] = $.trim($("#AddReagents-Input-Validity").val());
        jsonStr["ValidityUnit"] = $.trim($("#AddReagents-Input-ValidityUnit").find("option:selected").text());

        $.post("postAddReagents", {
            jsonStr: JSON.stringify(jsonStr)
        }, function (data) {
            alert(data);
        });

    });

    $("#AddReagents-cancel").click(function () {
        var modalID = $("#AddReagents-Parent-ModalID").html();
        $("#" + modalID).modal('hide');
    });

</script>
